package com.ly.talent.service.impl;

import java.util.List;
import com.ly.common.utils.DateUtils;
import com.ly.talent.domain.TalentSpecialty;
import com.ly.talent.mapper.TalentSpecialtyMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ly.talent.mapper.TalentUniversityMapper;
import com.ly.talent.domain.TalentUniversity;
import com.ly.talent.service.ITalentUniversityService;

/**
 * 学校信息Service业务层处理
 * 
 * @author sfli
 * @date 2021-03-02
 */
@Service
public class TalentUniversityServiceImpl implements ITalentUniversityService 
{
    @Autowired
    private TalentUniversityMapper talentUniversityMapper;
    @Autowired
    private TalentSpecialtyMapper talentSpecialtyMapper;
    /**
     * 查询学校信息
     * 
     * @param id 学校信息ID
     * @return 学校信息
     */
    @Override
    public TalentUniversity selectTalentUniversityById(Long id)
    {
        return talentUniversityMapper.selectTalentUniversityById(id);
    }

    /**
     * 查询学校信息列表
     * 
     * @param talentUniversity 学校信息
     * @return 学校信息
     */
    @Override
    public List<TalentUniversity> selectTalentUniversityList(TalentUniversity talentUniversity)
    {
        List<TalentUniversity> list = talentUniversityMapper.selectTalentUniversityList(talentUniversity);
        if("china".equals(talentUniversity.getType())){
            for(int i=0;i<list.size();i++){
                TalentSpecialty talentSpecialty = new TalentSpecialty();
                talentSpecialty.setTalentUniversityId(list.get(i).getId());
                list.get(i).setTalentSpecialtyList(talentSpecialtyMapper.selectTalentSpecialtyList(talentSpecialty));
            }
        }
        return list;
    }

    /**
     * 新增学校信息
     * 
     * @param talentUniversity 学校信息
     * @return 结果
     */
    @Override
    public int insertTalentUniversity(TalentUniversity talentUniversity)
    {
        talentUniversity.setCreateTime(DateUtils.getNowDate());
        return talentUniversityMapper.insertTalentUniversity(talentUniversity);
    }

    /**
     * 修改学校信息
     * 
     * @param talentUniversity 学校信息
     * @return 结果
     */
    @Override
    public int updateTalentUniversity(TalentUniversity talentUniversity)
    {
        talentUniversity.setUpdateTime(DateUtils.getNowDate());
        return talentUniversityMapper.updateTalentUniversity(talentUniversity);
    }

    /**
     * 批量删除学校信息
     * 
     * @param ids 需要删除的学校信息ID
     * @return 结果
     */
    @Override
    public int deleteTalentUniversityByIds(Long[] ids)
    {
        return talentUniversityMapper.deleteTalentUniversityByIds(ids);
    }

    /**
     * 删除学校信息信息
     * 
     * @param id 学校信息ID
     * @return 结果
     */
    @Override
    public int deleteTalentUniversityById(Long id)
    {
        return talentUniversityMapper.deleteTalentUniversityById(id);
    }
}
